---
abstractspacing: double
fontsize: 12pt
margin: 2cm
urlcolor: darkblue
linkcolor: Mahogany
citecolor: Mahogany
spacing: single
bibliography: references.bib
biblio-style: apalike
output:
  pdf_document:
    citation_package: natbib
    fig_caption: no
    number_sections: no
    keep_tex: no
    toc: no
    toc_depth: 3
    template: article-template.latex
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE,cache=TRUE)
knitr::opts_chunk$set(fig.width=7, fig.height=6, out.width = '70%', fig.align = "center") 
rm(list=ls())
library(remotes)
library(kableExtra)
library(haven)
library(tidyverse)
library(ivmodel)
library(doParallel)
library(foreach)
library(estimatr)
require(AER)
library(lfe)
library(glue)
#path <- "/Users/ziwenzu/Dropbox/research/IV/IV Sensitivity/LLXZ_rep"
path <- "~/Dropbox/ProjectZ/IV Sensitivity/LLXZ_rep"
setwd(path)
knitr::opts_knit$set(root.dir = path)
#install_github("apoorvalal/ivDiag")
library(ivDiag)
# number of cores
cores <- 15
```

## @kapoor2018

| Replication Summary | |
|----------------|---------------------------|
| Unit of analysis | constituency\*election |
| Treatment | number of independent candidates |
| Instrument | changes in entry costs |
| Outcome | voter turnout |
| Model | Table4(b5) |

```{r apsr_Kapoor_etal_2018}
df<-readRDS("./rawdata/apsr_Kapoor_etal_2018.rds")
D <-'CitCand'
Y <- "Turnout"
Z <- "UnScheduledDepChange"
controls <- c("CitCandBaseTrend", "CitCandBaseTrendSq", "CitCandBaseTrendCu",
              "CitCandBaseTrendQu",  "TurnoutBaseTrend", "TurnoutBaseTrendSq",
              "TurnoutBaseTrendCu", "TurnoutBaseTrendQu", "LnElectors",
              "LagWinDist", "LagWinDistSq", "LagWinDistCu",
              "LagWinDistQu", "LagTightElection")
cl<- "constituency"
FE <- c("year","constituency")
weights<-NULL
(g<-ivDiag(data=df, Y=Y, D=D, Z=Z, controls=controls, FE =FE, 
  cl =cl,weights=weights, cores = cores))
```

```{r, cache = FALSE}
plot_coef(g)
```

```{r apsr_Kapoor_etal_2018_sav, echo = FALSE}
save(g, file="./estimate/Kapoor2018.RData")
```

